/**
 * Created by JetBrains WebStorm.
 * User: Silence
 * Date: 3/18/12
 * Time: 9:05 AM
 * To change this template use File | Settings | File Templates.
 */

Ext.define('EM.controller.event.EventWindowController', {
    extend: 'Ext.app.Controller',
    models: ['person.Person', 'budget.BudgetTree'],
    views: ['event.EventWindowView', 'event.EventBasicView', 'event.EventPeopleView', 'event.AddPeopleView',
            'event.AllPeopleView', 'event.SpecificView', 'event.EventBudgetView',
            'event.BudgetTreePanel', 'event.ItemDetailPanel', 'event.SourcePanel'],
    init: function() {
        var view = Ext.getCmp('addpeopleview');
        if (!view) view = Ext.widget('addpeopleview');
        view.hide();
        this.control({
            'button[action=changepanel]': {
                toggle: function(button) {
                    if (button.pressed) {
                        Ext.getCmp('eventwindow').getLayout().setActiveItem(button.id + 'view');
                    }
                }
            },
            '#peoplemenu': {
                click: this.changePeopleList
            }
        });
    },
    changePeopleList: function(menu, item) {
        Ext.getCmp('eventpeople').setText(item.text);
        if (item.text == 'All') {
            Ext.getCmp('eventpeopleview').getLayout().setActiveItem('peoplealllist');
        }
        else {
            Ext.getCmp('eventpeopleview').getLayout().setActiveItem('peoplespecificlist');
        }
        Ext.getCmp('eventpeopleview').updateStore(item.text);
    }
});